package com.qf;

import org.quartz.JobKey;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.StdScheduler;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * author:z
 * time:2022/1/5 23:03
 * description:演示添加任务执行一段时间
 *  * 然后用代码控制删除任务, 不执行任务了
 */
public class TestSpringQuartzDelete {
    public static void main(String[] args) throws Exception {
        //加载spring核心配置文件,启动spring执行
        ApplicationContext applicationContext=new ClassPathXmlApplicationContext("ApplicationContext.xml");
        System.out.println("初始化执行完毕，开始执行定时器");

        //获取调度器对象
        Scheduler scheduler = (Scheduler) applicationContext.getBean("scheduler");
        System.out.println(scheduler.getClass());
        Thread.sleep(3000);

        //删除任务
        scheduler.deleteJob(JobKey.jobKey("job1","group1"));

    }
}
